﻿namespace TowerOfHanoi
{
    internal class Program
    {
        /// <summary>
        /// 汉诺塔
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.Write("请输入汉诺塔的层数：");
            int n = Convert.ToInt16(Console.ReadLine());
            Hanoi(n, 'A', 'B', 'C');
            Console.ReadKey();
        }
        static void Hanoi(int n,char source, char target, char auxiliary)
        {
            //n=1时，直接从起始柱移到目标柱
            if (n == 1)
                Console.WriteLine($"{n}:{source}->{target}");

            else
            {
                //n>1时，递归调用Hanoi函数，将n-1个圆盘从起始柱移到辅助柱
                Hanoi(n - 1, source, auxiliary, target);
                //n>1时，将第n个圆盘从起始柱移到目标柱
                Console.WriteLine($"{n}:{source}->{target}");
                //n>1时，将n-1个圆盘从辅助柱移到目标柱
                Hanoi(n - 1, auxiliary, target, source);
            }
        }

    }
}